home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zmisc3.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.9 KB  |  149 lines

  1. /* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zmisc3.c,v 1.2 2000/09/19 19:00:55 lpd Exp $ */
  20. /* Miscellaneous LanguageLevel 3 operators */
  21. #include "ghost.h"
  22. #include "gscspace.h"        /* for gscolor2.h */
  23. #include "gsmatrix.h"        /* ditto */
  24. #include "gsclipsr.h"
  25. #include "gscolor2.h"
  26. #include "gscssub.h"
  27. #include "oper.h"
  28. #include "igstate.h"
  29. #include "store.h"
  30.  
  31. /* - clipsave - */
  32. private int
  33. zclipsave(i_ctx_t *i_ctx_p)
  34. {
  35.     return gs_clipsave(igs);
  36. }
  37.  
  38. /* - cliprestore - */
  39. private int
  40. zcliprestore(i_ctx_t *i_ctx_p)
  41. {
  42.     return gs_cliprestore(igs);
  43. }
  44.  
  45. /* <proc1> <proc2> .eqproc <bool> */
  46. /*
  47.  * Test whether two procedures are equal to depth 10.
  48.  * This is the equality test used by idiom recognition in 'bind'.
  49.  */
  50. #define MAX_DEPTH 10        /* depth is per Adobe specification */
  51. typedef struct ref2_s {
  52.     ref proc1, proc2;
  53. } ref2_t;
  54. private int
  55. zeqproc(i_ctx_t *i_ctx_p)
  56. {
  57.     os_ptr op = osp;
  58.     ref2_t stack[MAX_DEPTH + 1];
  59.     ref2_t *top = stack;
  60.  
  61.     make_array(&stack[0].proc1, 0, 1, op - 1);
  62.     make_array(&stack[0].proc2, 0, 1, op);
  63.     for (;;) {
  64.     long i;
  65.  
  66.     if (r_size(&top->proc1) == 0) {
  67.         /* Finished these arrays, go up to next level. */
  68.         if (top == stack) {
  69.         /* We're done matching: it succeeded. */
  70.         make_true(op - 1);
  71.         pop(1);
  72.         return 0;
  73.         }
  74.         --top;
  75.         continue;
  76.     }
  77.     /* Look at the next elements of the arrays. */
  78.     i = r_size(&top->proc1) - 1;
  79.     array_get(&top->proc1, i, &top[1].proc1);
  80.     array_get(&top->proc2, i, &top[1].proc2);
  81.     r_dec_size(&top->proc1, 1);
  82.     ++top;
  83.     /*
  84.      * Amazingly enough, the objects' executable attributes are not
  85.      * required to match.  This means { x load } will match { /x load },
  86.      * even though this is clearly wrong.
  87.      */
  88. #if 0
  89.     if (r_has_attr(&top->proc1, a_executable) !=
  90.         r_has_attr(&top->proc2, a_executable)
  91.         )
  92.         break;
  93. #endif
  94.     if (obj_eq(&top->proc1, &top->proc2)) {
  95.         /* Names don't match strings. */
  96.         if (r_type(&top->proc1) != r_type(&top->proc2) &&
  97.         (r_type(&top->proc1) == t_name ||
  98.          r_type(&top->proc2) == t_name)
  99.         )
  100.         break;
  101.         --top;        /* no recursion */
  102.         continue;
  103.     }
  104.     if (r_is_array(&top->proc1) && r_is_array(&top->proc2) &&
  105.         r_size(&top->proc1) == r_size(&top->proc2) &&
  106.         top < stack + (MAX_DEPTH - 1)
  107.         ) {
  108.         /* Descend into the arrays. */
  109.         continue;
  110.     }
  111.     break;
  112.     }
  113.     /* An exit from the loop indicates that matching failed. */
  114.     make_false(op - 1);
  115.     pop(1);
  116.     return 0;
  117. }
  118.  
  119. /* <index> <bool> .setsubstitutecolorspace - */
  120. private int
  121. zsetsubstitutecolorspace(i_ctx_t *i_ctx_p)
  122. {
  123.     os_ptr op = osp;
  124.     int index, code;
  125.  
  126.     check_type(*op, t_boolean);
  127.     check_int_leu(op[-1], 2);
  128.     index = (int)op[-1].value.intval;
  129.     code = gs_setsubstitutecolorspace(igs, index,
  130.                       (op->value.boolval ?
  131.                        gs_currentcolorspace(igs) :
  132.                        NULL));
  133.     if (code >= 0)
  134.     pop(2);
  135.     return code;
  136. }
  137.  
  138. /* ------ Initialization procedure ------ */
  139.  
  140. const op_def zmisc3_op_defs[] =
  141. {
  142.     op_def_begin_ll3(),
  143.     {"0cliprestore", zcliprestore},
  144.     {"0clipsave", zclipsave},
  145.     {"2.eqproc", zeqproc},
  146.     {"2.setsubstitutecolorspace", zsetsubstitutecolorspace},
  147.     op_def_end(0)
  148. };
  149.